#include "RandomNode.h"
#include "IdNode.h"

namespace jcrada {

    RandomNode::RandomNode() {

    }

    RandomNode::~RandomNode() {

    }

    TerminalNode* RandomNode::nextTerminal(int min, int max) {
        TerminalNode* result = new TerminalNode();
        result->setValue(_rnd_terminal.nextInt(min, max));
        return result;
    }

    FunctionNode* RandomNode::nextFunction(int arity) {
        FunctionNode* result = new FunctionNode(arity);
        int function = _rnd_function.nextInt(0, FunctionNode::FT_COUNT);
        result->setType((FunctionNode::eFunctionType)function);
        return result;
    }

    Node* RandomNode::next(int min, int max, int arity) {
        if (_random.nextBool()) {
            return nextTerminal(min, max);
        }
        return nextFunction(arity);
    }
}
